package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysUnit;
import com.ruoyi.system.service.ISysUnitService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品单位信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-22
 */
@RestController
@RequestMapping("/system/unit")
public class SysUnitController extends BaseController
{
    @Autowired
    private ISysUnitService sysUnitService;

    /**
     * 查询商品单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:unit:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUnit sysUnit)
    {
        startPage();
        List<SysUnit> list = sysUnitService.selectSysUnitList(sysUnit);
        return getDataTable(list);
    }

    /**
     * 导出商品单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:unit:export')")
    @Log(title = "商品单位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUnit sysUnit)
    {
        List<SysUnit> list = sysUnitService.selectSysUnitList(sysUnit);
        ExcelUtil<SysUnit> util = new ExcelUtil<SysUnit>(SysUnit.class);
        util.exportExcel(response, list, "商品单位信息数据");
    }

    /**
     * 获取商品单位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:unit:query')")
    @GetMapping(value = "/{unitId}")
    public AjaxResult getInfo(@PathVariable("unitId") Long unitId)
    {
        return success(sysUnitService.selectSysUnitByUnitId(unitId));
    }

    /**
     * 新增商品单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:unit:add')")
    @Log(title = "商品单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUnit sysUnit)
    {
        return toAjax(sysUnitService.insertSysUnit(sysUnit));
    }

    /**
     * 修改商品单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:unit:edit')")
    @Log(title = "商品单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUnit sysUnit)
    {
        return toAjax(sysUnitService.updateSysUnit(sysUnit));
    }

    /**
     * 删除商品单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:unit:remove')")
    @Log(title = "商品单位信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{unitIds}")
    public AjaxResult remove(@PathVariable Long[] unitIds)
    {
        return toAjax(sysUnitService.deleteSysUnitByUnitIds(unitIds));
    }
}
